export const getMetaBooleanParam=(value:any,defaultValue:boolean)=>{
    let param=defaultValue;
    if (value != null && value.trim() !== "") {
        param = value.trim() === "true"
    }
    return param;
}

export const getMetaParam = (data: string, key: string) => {
    const reg = new RegExp(`export\\s+const\\s+${key}\\s*=(.*?)[\r\n]`, "g")
    const matchResult = data.match(reg) // 注意这里使用非全局模式
    if (matchResult == null) {
        return matchResult
    }
    let metaDataStr = matchResult[0];
    const reg2 = new RegExp(`export\\s+const\\s+${key}\\s*=`, "g")
    metaDataStr = metaDataStr.replace(reg2, '').replace(";", '').replace("\n", '').replace('\r', ''); // 格式化字符串
    return metaDataStr
}


export const checkNormalLayout = (excludeList:string[]) => {
    const regList = excludeList.map(item => new RegExp(item));
    return (view:string) => {
        const result = regList.some(reg => reg.test(view));
        return !result;
    }
}

export const format = (str: string, data: Record<string, any>): string => {
    return str.replace(/{(\w+)}/g, (_match, key) => data[key]);
}

export const strToRegex = (str: string) => {
    // 处理特殊字符的转义
    str = str.replace(/\[/g, '\\[').replace(/\]/g, '\\]').replace(/\{/g, '\\{').replace(/\}/g, '\\}').replace(/\(/g, '\\(').replace(/\)/g, '\\)');

    // 将 * 转换为匹配任意字符零次或多次的正则表达式符号
    str = str.replace(/\*\*/g, '.*').replace(/\*/g, '[^/]*');

    // 处理字符类
    str = str.replace(/\[([^\]]+)\]/g, '[$1]');

    return new RegExp(str);
}
